# 有个银行账号的例子，我们要确保没人能设置金额为负，并且有个只读属性 cny 返回换算人民币后的金额。

class Account(object):
    """
    账号类,
    amount 是美元金额.
    """
    def __init__(self, rate):
        self.__amt = 0
        self.rate = rate

    @property
    def amount(self):
        """账户余额（美元）"""
        return self.__amt

    @property
    def cny(self):
        """账户余额（人名币）"""
        return self.__amt * self.rate

    @amount.setter
    def amount(self, value):
        if value < 0:
            print('Sorry, no negative amount in the account.')
            return
        self.__amt = value


if __name__ == '__main__':
    acc = Account(rate=6.6)  # 设定比例
    acc.amount = 20

    print("Dollar amount:", acc.amount)
    print("In CNY:", acc.cny)
    acc.amount = -100
    print("Dollar amount:", acc.amount)
